package com.yanqu.road.server.cmd.minewar.task;

import com.yanqu.road.server.pb.MineWarPb;
import com.yanqu.road.entity.minewar.UserMinePit;
import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.server.cmd.base.BaseTask;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.MineWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

public class GetUserPitListTask extends BaseTask {

    private long userId;

    private List<UserMinePit> pitList;

    public GetUserPitListTask(YanQuMessage packet, GamePlayer player) {
        super(packet, player);
    }

    @Override
    protected boolean parseData() throws Exception {
        MineWarProto.MineGetUserMinePitReqMsg reqMsg = MineWarProto.MineGetUserMinePitReqMsg.parseFrom(packet.getBytes());
        userId = reqMsg.getUserId();
        return true;
    }

    @Override
    protected void execute() {
        //校验查看用户是否在反击列表中
        if(MineWarMgr.isInMineWarRecord(player.getUserId(), userId)) {
            pitList = MineWarMgr.getUserMinePitList(userId);
        }
    }

    @Override
    protected void sendData(GamePlayer player) {
        MineWarProto.MinePitListMsg.Builder respMsg = MineWarPb.parseMinePitListMsg(pitList);
        player.sendPacket(Protocol.U_MINE_WAR_GET_USER_PIT_DATA, respMsg);
    }
}
